<% layout('/layouts/default.html', {title: '额度设置', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-trophy"></i> ${text('额度设置')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${clinicSetting}" action="${ctx}/fl/clinicsetting/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('诊所')}：</label>
					<div class="control-inline width-120">
						<#form:select path="clinic.id" items="${clinicList}" itemLabel="name" itemValue="id"  class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('状态')}：</label>
					<div class="control-inline width-60">
						<#form:select path="status" dictType="sys_search_status" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
					<button type="button" onclick="mutiset()" class="btn btn-default btn-sm">${text('批量设置')}</button>
					
				</div>
			</#form:form>			
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text('诊所')}', name:'clinic.name', width:200, align:"center", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/fl/clinicsetting/form?id='+row.id+'" class="btnList" data-title="${text('设置')}">'+(val||row.id)+'</a>';
		}},
		{header:'${text('科室')}', name:'department', index:'a.department', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('fl_department')}, val, '未知', true);
		}},
		{header:'${text('可预约时间')}', name:'businessHours', index:'a.business_hours', width:450, align:"center", formatter: function(val, obj, row, act){
			return toLabel(val);
		}},

		{header:'${text('服务时间片')}', name:'serviceTime', index:'a.service_time', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('fl_service_time')}, val, '未知', true);
		}},
		{header:'${text('单位时间片服务人数')}', name:'number', index:'a.number', width:150, align:"center"},
		{header:'${text('科室介绍')}', name:'departmentDescription', index:'a.department_description', width:250, align:"center"},
		{header:'${text('状态')}', name:'status', index:'a.status', width:80, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_status')}, val, '未知', true);
		}},
		{header:'${text('操作')}', name:'actions', width:130, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('fl:clinic:edit')){ %>
				actions.push('<a href="${ctx}/fl/clinicsetting/form?id='+row.id+'" class="btnList" title="${text('设置')}"><i class="fa fa-pencil"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

function mutiset(){
	js.addTabPage(null, "批量额度设置", "${ctx}/fl/clinicsetting/formAll?clinicId=" + $("#clinic_id").val(), true, true);
}

function toLabel(businessHoursString){
	var businessHoursLabel = "";
	var businessHours;
	if(businessHoursString != null &&  businessHoursString.length>0){
		try{
			businessHours = JSON.parse(businessHoursString);
		}catch(e){
			businessHours = [];
		}
	}
	if(businessHours!=null && businessHours.length>0){													
		$.each(businessHours, function (idx, item) {
			if(item.amStart == -1 && item.pmStart == -1){
				
			}else if(item.amStart == -1){
				businessHoursLabel += "星期" + getWeekName(item.name)+":"+item.pmStart+"-" + item.pmEnd+";";
			}else if(item.pmStart == -1){
				businessHoursLabel += "星期" + getWeekName(item.name)+":"+item.amStart+"-" + item.amEnd+";";
			}else{
				businessHoursLabel += "星期" + getWeekName(item.name)+":"+item.amStart+"-" + item.amEnd +","+item.pmStart+"-" + item.pmEnd+";";
			}
		});
	}
	return businessHoursLabel;
}

function getWeekName(name){
	if(name == "1"){
		return "一";
	}else if(name == "2"){
		return "二";
	}else if(name == "3"){
		return "三";
	}else if(name == "4"){
		return "四";
	}else if(name == "5"){
		return "五";
	}else if(name == "6"){
		return "六";
	}else{
		return "日";
	}
}

</script>